﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace 学生成绩管理系统
{
    public partial class Login : Form
    {
        public Login()
        {
            InitializeComponent();
        }
        public static string name;
        private void button1_Click(object sender, EventArgs e)
        {
            string username, password;
            if (Username.Text.Trim() != "" && Password.Text.Trim() != "")
            {
                username = Username.Text.Trim();
                password = Password.Text.Trim();
                DataAccess data = new DataAccess();
                if (data.CheckAdmin(username, password))
                {
                    username = Username.Text.Trim();
                    name = username;

                    //判断是否以创建过主窗体
                    if (null == Frmcjgl.frmcjgl)
                    {
                        Frmcjgl.frmcjgl = new Frmcjgl();
                        Frmcjgl.frmcjgl.IsMdiContainer = true;
                    }
                    Frmcjgl.frmcjgl.Show();
                    this.Hide();
                }
                else
                {
                    MessageBox.Show("您输入的帐号或密码有误，请重新登录！");
                    Username.Text = "";
                    Password.Text = "";
                }
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        //窗体移动代码

        private Point mouseOffset;//记录鼠标指针的坐标
        private bool isMouseDown = false; //记录鼠标按键是否按下

        private void Login_MouseDown(object sender, MouseEventArgs e)
        {
            int xOffset;
            int yOffset;
            if (e.Button == MouseButtons.Left)
            {
                xOffset = -e.X;
                yOffset = -e.Y;
                mouseOffset = new Point(xOffset, yOffset);
                isMouseDown = true;
            }
        }

        private void Login_MouseMove(object sender, MouseEventArgs e)
        {
            if (isMouseDown)
            {
                Point mousePos = Control.MousePosition;
                mousePos.Offset(mouseOffset.X, mouseOffset.Y);
                this.Location = mousePos;
            }
        }

        private void Login_MouseUp(object sender, MouseEventArgs e)
        {
            //修改鼠标状态isMouseDown的值
            //确保只有鼠标左键按下并移动时，才移动窗体
            if (e.Button == MouseButtons.Left)
            {
                isMouseDown = false;
            }
        }
        //end 窗体移动代码
    }
}